
package Server;
import java.net.*;

/**
 * The server
 * @author Samuel Millar
 */
public class FlightServer extends Thread{
    private static final int SOCKET_NUMBER = 3120;
    private ServerSocket flightServerSocket;

    public static void main(String argv[]) {
        ServerGUI serverGui = new ServerGUI();
        serverGui.go();
    }

    public FlightServer() throws Exception {
        flightServerSocket = new ServerSocket(SOCKET_NUMBER);
    }
/**
     * Runs the server
     */
    public static void go(){
        try {
            FlightServer server = new FlightServer();
            server.run();
        }
        catch (Exception e){
            System.exit(-1);
        }
    }

    /**
     * Waits for a connection and starts a new thread to deal with the connection
     */
    public void run() {
        ServerGUI.appendText("\n" + "Waiting for connections." + "\n");
        while (true) {
            try {
                Socket client = flightServerSocket.accept();
                ServerGUI.appendText("Received a client connection from: "+ client.getInetAddress() + "\n");
                ClientConnection connection = new ClientConnection(client);
            }catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    }
}

